package com.m1book.domain.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.m1book.domain.user.Miser;
import com.m1book.repositories.user.MiserRepository;

@Service("miserDetailsService")
public class MiserDetailsService implements UserDetailsService {
	
	@Autowired
	private MiserRepository miserRepository;

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		Miser miser = miserRepository.findByAccount(username);
		
		if (miser == null) {
			throw new UsernameNotFoundException(username + " not found.");
		} else {
			return new MiserDetails(miser);
		}
	}


}
